package chapter_7;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Test16 {
    public static void main(String[] args) throws Exception {
        Dog[] dogs = new Dog[2];
        dogs[0] = new Dog("小黑",2,"黑色");
        dogs[1] = new Dog("小白",3,"黑色");
        FileOutputStream fos = new FileOutputStream("D:\\dog.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(dogs);
//        oos.writeObject(dogs);
        oos.close();

        FileInputStream fis = new FileInputStream("D:\\dog.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Dog[] o =(Dog[]) ois.readObject();
        for (Dog dog : o) {
            System.out.println(dog.getName()+" "+dog.getAge()+" "+dog.getColor());
        }
        ois.close();



    }
}
